package com.year_23.april;

/**
 * @Author jsh
 * @Date 2023/4/17 22:17
 * @Version 1.0
 */
public class Day17 {

    public static void main(String[] args) {
        countDaysTogether("08-15",
                "08-18",
                "08-16",
                "08-19");
    }

    public static int countDaysTogether(String arriveAlice, String leaveAlice, String arriveBob, String leaveBob) {
        int dateOfMouths[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};

        int[] mouthDays = new int[13];
        for (int i = 0; i < 12; i++) {
            mouthDays[i+1] = mouthDays[i] + dateOfMouths[i];
        }
        int arriveAliceDay = calculateDayOfYear(arriveAlice, mouthDays);
        int leaveAliceDay = calculateDayOfYear(leaveAlice, mouthDays);
        int arriveBobDay = calculateDayOfYear(arriveBob, mouthDays);
        int leaveBobDay = calculateDayOfYear(leaveBob, mouthDays);


        return Math.max(0, (Math.min(leaveAliceDay, leaveBobDay) - Math.max(arriveAliceDay, arriveBobDay)+1));
    }

    public static int calculateDayOfYear(String day, int[] mouthDays){
        String[] days = day.split("-");
        Integer month = Integer.valueOf(days[0]);
        Integer date = Integer.valueOf(days[1]);
        return mouthDays[month -1] + date;
    }

}
